//
//  String+Extension.swift
//  fruit-helper-swift
//
//  Created by 赵隆杰 on 2022/6/21.
//

import Foundation
import UIKit

extension String {
    //Base64转UIImage
    static func convertStrToImage(_ imageStr:String) ->UIImage?{
       if let data: NSData = NSData(base64Encoded: imageStr, options:NSData.Base64DecodingOptions.ignoreUnknownCharacters)
       {
           if let image: UIImage = UIImage(data: data as Data)
           {
               return image
           }
       }
       return nil
    }

       
    //UIImage转Base64
    static func getStrFromImage(_ image:UIImage) -> String{
        let dataTmp = image.jpegData(compressionQuality: 0.3)
        if let data = dataTmp {
            let imageStrTT = data.base64EncodedString()
            return imageStrTT
        }
       return ""
    }

}

